package com.ajx.blog.service.impl;

import com.ajx.blog.entity.FocusInfo;
import com.ajx.blog.mapper.FocusInfoMapper;
import com.ajx.blog.service.api.FocusInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FocusInfoServiceImpl extends ServiceImpl<FocusInfoMapper, FocusInfo> implements FocusInfoService {

    @Autowired
    private FocusInfoMapper focusInfoMapper;

    @Transactional(readOnly = true)
    @Override
    public List<FocusInfo> selectTargetUid(Integer bloguid) {
        QueryWrapper<FocusInfo> qw = new QueryWrapper<>();
        qw.eq("target_uid", bloguid);
        return focusInfoMapper.selectList(qw);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void addConcern(Integer bloguid, Integer uid) {
        focusInfoMapper.insertConcerns(bloguid, uid);
    }

    @Override
    public boolean selectExsit(Integer uid, Integer bloguid) {
        QueryWrapper<FocusInfo> focusInfoQueryWrapper = new QueryWrapper<>();
        focusInfoQueryWrapper.eq("target_uid", bloguid).eq("source_uid",uid);
        focusInfoQueryWrapper.eq("target_uid", bloguid).eq("source_uid", uid);
        return focusInfoMapper.selectOne(focusInfoQueryWrapper) != null;
    }

}
